//请实现一个函数，把字符串 s 中的每个空格替换成"%20"。 
//
// 
//
// 示例 1： 
//
// 输入：s = "We are happy."
//输出："We%20are%20happy." 
//
// 
//
// 限制： 
//
// 0 <= s 的长度 <= 10000 
// 👍 35 👎 0

package leetcode.editor.cn;

import common.util.MyUtil;

/**
 * Java：替换空格
 *
 * @author changgui
 */
@SuppressWarnings("all")
public class P剑指_offer_05_TiHuanKongGeLcof {
    public static void main(String[] args) {
        Solution solution = new P剑指_offer_05_TiHuanKongGeLcof().new Solution();
        String s = " ";
        MyUtil.print(solution.replaceSpace(s));

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String replaceSpace(String s) {
            if (s == null || "".equals(s)) {
                return s;
            }
            char[] arr = new char[s.length() * 3];
            int index = 0;
            for (char c : s.toCharArray()) {
                if (c == ' ') {
                    arr[index++] = '%';
                    arr[index++] = '2';
                    arr[index++] = '0';
                } else {
                    arr[index++] = c;
                }
            }
            return new String(arr, 0, index);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}